/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.msk.sys.service;

import com.msk.common.core.redis.RedisCache;
import com.msk.sys.domain.Dict;
import com.msk.sys.mapper.DictDao;
import com.msk.sys.utils.DictMskUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 字典Service
 * @author ThinkGem
 * @version 2014-05-16
 */
@Service
@Transactional(readOnly = true)
public class DictService extends CrudService<DictDao, Dict> {

	@Autowired
	private RedisCache redisService;

	/**
	 * 查询字段类型列表
	 * @return
	 */
	public List<String> findTypeList() {
		return dao.findTypeList(new Dict());
	}

	@PostConstruct
	public void initNotExistDictList() {
		DictMskUtils.initNotExistDictList(null);
	}

	@Transactional(readOnly = false)
	public void save(Dict dict) {
		super.save(dict);
		// 数据字典缓存
		redisService.setCacheMapValue(DictMskUtils.CACHE_DICT_MAP, dict.getType(), dict);
	}

	@Transactional(readOnly = false)
	public void delete(Dict dict) {
		super.delete(dict);
		redisService.deleteCacheMapValue(DictMskUtils.CACHE_DICT_MAP, dict.getType());
	}

	public Dict findByType(String value, String type){
		return dao.findByType(value,type);
	};

	public String findByTypeAndLabel(String label, String type){
		return dao.findByTypeAndLabel(label,type);
	}
}
